import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'


const countrSlice = createSlice({
  name: 'counter',
  initialState: {
    value: 2,
    states: 'idle'
  },
  reducers: {
    add: (states) => {
      states.value += 1
    },

    decrement: (states) => {
      states.value -=1
    },

    incrementByAmount: (states, action) => {
      states.value += action.payload
    }
  },
})

export const postUserData = createAsyncThunk('counter/postUserData', async (): Promise<string>  => {
  return new Promise((resove, reject) => {
    resove('请求成功')
  })
})

export const { add, decrement, incrementByAmount } = countrSlice.actions
export default countrSlice.reducer